/**
 * 基于wx的小程序网络请求封装类
 *
 */

import Fingerprint2 from 'fingerprintjs2'

/**
 * 从服务器获取AccessToken的方法
 */
export const getFingerprintID = () => {
  return new Promise((resolve, reject) => {
    Fingerprint2.get(async function (components) {
      const values = components.map((component) => {
        return component.value
      })
      const murmur = Fingerprint2.x64hash128(values.join(''), 31)
      return resolve(murmur)
    })
  })
}

export const device = () => {
  let agent = navigator.userAgent
  if (agent.indexOf('Android') > -1 || agent.indexOf('Adr') > -1) {
    return 'android'
  } else if (agent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
    return 'ios'
  }
  return 'web'
}

// export default class FingerPrint {
//   constructor () {
//     this.name = 'JSBridge'
//     this.reset = true
//     this.instance = null
//     this.userAgent = 'h5'
//   }
//   static async getSn () {
//     return new Promise((resolve, reject) => {
//       Fingerprint2.get(async function (components) {
//         const values = components.map((component) => {
//           return component.value
//         })
//         const murmur = Fingerprint2.x64hash128(values.join(''), 31)
//         return resolve(murmur)
//       })
//     })
//   }
// }
